
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/24/2014 18:07:22
-- Generated from EDMX file: C:\Users\A506033\documents\visual studio 2012\Projects\SeriesTheque\SeriesTheque.Data\SeriesThequeModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [db_seriestheque];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_SeasonEpisode]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Episodes] DROP CONSTRAINT [FK_SeasonEpisode];
GO
IF OBJECT_ID(N'[dbo].[FK_SerieSeason]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Seasons] DROP CONSTRAINT [FK_SerieSeason];
GO
IF OBJECT_ID(N'[dbo].[FK_UserSeries]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Series] DROP CONSTRAINT [FK_UserSeries];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Episodes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Episodes];
GO
IF OBJECT_ID(N'[dbo].[Seasons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Seasons];
GO
IF OBJECT_ID(N'[dbo].[Series]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Series];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Episodes'
CREATE TABLE [dbo].[Episodes] (
    [Episode_Id] int  NOT NULL,
    [Episode_Number] nvarchar(max)  NOT NULL,
    [Episode_Date] datetime  NOT NULL,
    [Episode_Enable] bit  NOT NULL,
    [Seasons_Season_Id] int  NOT NULL
);
GO

-- Creating table 'Seasons'
CREATE TABLE [dbo].[Seasons] (
    [Season_Id] int  NOT NULL,
    [Season_Date] datetime  NOT NULL,
    [Season_Enable] bit  NOT NULL,
    [Series_Serie_Id] int  NOT NULL
);
GO

-- Creating table 'Series'
CREATE TABLE [dbo].[Series] (
    [Serie_Id] int  NOT NULL,
    [Serie_name] nvarchar(max)  NOT NULL,
    [Serie_Date] datetime  NOT NULL,
    [Serie_Enable] bit  NOT NULL,
    [User_User_Id] smallint  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [User_Login] nvarchar(max)  NOT NULL,
    [User_Passwrd] nvarchar(max)  NOT NULL,
    [User_date] datetime  NOT NULL,
    [User_Enable] bit  NOT NULL,
    [User_Id] smallint IDENTITY(1,1) NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Episode_Id] in table 'Episodes'
ALTER TABLE [dbo].[Episodes]
ADD CONSTRAINT [PK_Episodes]
    PRIMARY KEY CLUSTERED ([Episode_Id] ASC);
GO

-- Creating primary key on [Season_Id] in table 'Seasons'
ALTER TABLE [dbo].[Seasons]
ADD CONSTRAINT [PK_Seasons]
    PRIMARY KEY CLUSTERED ([Season_Id] ASC);
GO

-- Creating primary key on [Serie_Id] in table 'Series'
ALTER TABLE [dbo].[Series]
ADD CONSTRAINT [PK_Series]
    PRIMARY KEY CLUSTERED ([Serie_Id] ASC);
GO

-- Creating primary key on [User_Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([User_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Seasons_Season_Id] in table 'Episodes'
ALTER TABLE [dbo].[Episodes]
ADD CONSTRAINT [FK_SeasonEpisode]
    FOREIGN KEY ([Seasons_Season_Id])
    REFERENCES [dbo].[Seasons]
        ([Season_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SeasonEpisode'
CREATE INDEX [IX_FK_SeasonEpisode]
ON [dbo].[Episodes]
    ([Seasons_Season_Id]);
GO

-- Creating foreign key on [Series_Serie_Id] in table 'Seasons'
ALTER TABLE [dbo].[Seasons]
ADD CONSTRAINT [FK_SerieSeason]
    FOREIGN KEY ([Series_Serie_Id])
    REFERENCES [dbo].[Series]
        ([Serie_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SerieSeason'
CREATE INDEX [IX_FK_SerieSeason]
ON [dbo].[Seasons]
    ([Series_Serie_Id]);
GO

-- Creating foreign key on [User_User_Id] in table 'Series'
ALTER TABLE [dbo].[Series]
ADD CONSTRAINT [FK_UserSeries]
    FOREIGN KEY ([User_User_Id])
    REFERENCES [dbo].[Users]
        ([User_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserSeries'
CREATE INDEX [IX_FK_UserSeries]
ON [dbo].[Series]
    ([User_User_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------